


package com.gc.server.controller;

import com.yf.request.SearchParam;

import java.io.IOException;
import java.util.List;

import com.yf.response.RRException;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.yf.annotation.SysLog;
import com.gc.server.vo.UserSchoolVo;
import com.gc.server.service.UserSchoolService;
import com.yf.response.R;

import javax.servlet.http.HttpServletResponse;
import java.util.HashMap;

import org.springframework.web.multipart.MultipartFile;

/**
 * 用户学校关系Controller
 *
 * @author hxf
 * @email 505860922@qq.com
 * @date ${datetime}
 */
@RestController
@RequestMapping("/user/school")
public class UserSchoolController {
    @Autowired
    private UserSchoolService userSchoolService;

    /**
     * 列表用户学校关系
     */
    @SysLog("查看用户学校关系")
    @RequestMapping("/list")
    @RequiresPermissions("user:school:list")
    public R list(@RequestBody SearchParam<UserSchoolVo> params) {
        PageHelper.startPage(params.getPage(), params.getLimit()).setOrderBy(params.getOrder());
        List<UserSchoolVo> list = userSchoolService.findVo(params.getEntity());
        return R.ok(new PageInfo(list));
    }

    /**
     * 下载
     */
    @SysLog("下载")
    @RequestMapping("/down")
    @RequiresPermissions("user:school:list")
    public void down(@RequestBody SearchParam<UserSchoolVo> params, HttpServletResponse response) {
        List<UserSchoolVo> list = userSchoolService.findVo(params.getEntity());
        userSchoolService.downLoad(response, list);
    }

    /**
     * 上传
     *
     * @param file
     */
    @RequestMapping("/upload")
    public void upload(MultipartFile file) {
        try {
            userSchoolService.upload(file.getInputStream());
        } catch (IOException e) {
            throw new RRException("上传的文件有误!");
        }
    }


    /**
     * 查看用户学校关系
     */
    @SysLog("查看用户学校关系")
    @RequestMapping("/info/{id}")
    @RequiresPermissions("user:school:info")
    public R info(@PathVariable("id") Long id) {
        UserSchoolVo vo = userSchoolService.getVo(id);

        return R.ok(vo);
    }

    /**
     * 保存用户学校关系
     */
    @SysLog("保存用户学校关系")
    @RequestMapping("/save")
    @RequiresPermissions("user:school:save")
    public R save(@RequestBody UserSchoolVo vo) {
        userSchoolService.saveVo(vo);
        return R.ok(vo);
    }

    /**
     * 修改用户学校关系
     */
    @SysLog("修改用户学校关系")
    @RequestMapping("/update")
    @RequiresPermissions("user:school:update")
    public R update(@RequestBody UserSchoolVo vo) {
        userSchoolService.updateVo(vo);

        return R.ok(vo);
    }

    /**
     * 删除用户学校关系
     */
    @SysLog("删除用户学校关系")
    @RequestMapping("/delete")
    @RequiresPermissions("user:school:delete")
    public R delete(Long[] ids) {
        userSchoolService.deleteBatch(ids);

        return R.ok();
    }

    /**
     * 所有用户学校关系
     */
    @SysLog("所有用户学校关系")
    @RequestMapping("/all")
    public R all(String order) {
        PageHelper.orderBy(order != null ? order : "id desc");
        List<UserSchoolVo> list = userSchoolService.findVo(null);
        return R.ok(list);
    }

    /**
     * 所有enums
     */
    @SysLog("所有enums")
    @RequestMapping("/dmz/options")
    public R options() {
        HashMap<String, Object> options = new HashMap();
        return R.ok(options);
    }


    /***********自定义开始***********/
}
